package com.topfun.dao;

import com.topfun.utils.JDBCUtil;
import com.topfun.vo.payment.ChargeOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by huangda on 2017/8/21.
 * 支付dao
 */
public class PaymentDao {
    // ===========================================================
    // Constants
    // ===========================================================
    private static final Logger logger = LoggerFactory.getLogger(PaymentDao.class);

    private static final String SQL_INSERT_CHARGE_ORDER;
    private static final String SQL_QUERY_CHARGE_ORDER_BY_ORDERID;
    private static final String SQL_UPDATE_CHARGE_ORDER_STATUS;

    static {
        SQL_INSERT_CHARGE_ORDER = "insert into topfun.charge_order " +
                "(orderId,userId,ip,payType,amount," +
                "subject,description,currency,country,status,remark,orderTime) " +
                "values (?,?,?,?,?," +
                "?,?,?,?,?,?,?)";
        SQL_QUERY_CHARGE_ORDER_BY_ORDERID = "SELECT orderId,userId,ip,payType,amount,subject,description,currency,country,status,remark,orderTime from topfun.charge_order where orderId = ?";
        SQL_UPDATE_CHARGE_ORDER_STATUS = "update topfun.charge_order set status = ? , remark = ? where orderId = ?";
    }
    // ===========================================================
    // Fields
    // ===========================================================

    // ===========================================================
    // Constructors
    // ===========================================================

    // ===========================================================
    // Getter &amp; Setter
    // ===========================================================

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    public static void insertChargeOrder(ChargeOrder pChargeOrder) {
        JDBCUtil.insertForPrimaryKey(SQL_INSERT_CHARGE_ORDER,new Object[]{
                //orderId,userId,ip,payType,amount
                pChargeOrder.orderId,pChargeOrder.userId,pChargeOrder.ip,pChargeOrder.payType,pChargeOrder.amount,
                //subject,description,currency,
                pChargeOrder.subject,pChargeOrder.description,pChargeOrder.currency,
                //country,status,remark,orderTime
                pChargeOrder.country,pChargeOrder.status,pChargeOrder.remark,pChargeOrder.orderTime
        });
    }

    public static ChargeOrder queryChargeOrderByOrderId(String pOrderId) {
        return JDBCUtil.queryForOne(ChargeOrder.class,SQL_QUERY_CHARGE_ORDER_BY_ORDERID,new Object[]{pOrderId});
    }

    public static int updateChargeOrderStatus(String pOrderId, int pStatus, String pRemark) {
        return JDBCUtil.update(SQL_UPDATE_CHARGE_ORDER_STATUS,new Object[]{pStatus,pRemark,pOrderId});
    }


    // ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================
}
